package com.itholmes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.itholmes.pojo.User;
import com.itholmes.utils.ConnectionsPool;
import com.itholmes.utils.JDBCUtils;

public class UserDaoSelectOne implements UserDao{
	
	public User getSelectNameOne(String user_name) {
		User user = new User();
		Connection connection = JDBCUtils.getConnection();
		
		PreparedStatement pre = null;
		ResultSet rs = null;
		try {
			pre = connection.prepareStatement("select * from user where user_name = ?");
			pre.setString(1, user_name);
			
			rs = pre.executeQuery();
			while(rs.next()) {
				user.setUser_id(rs.getInt("user_id"));
				user.setUser_name(rs.getString("user_name"));
				user.setUser_password(rs.getString("user_password"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		JDBCUtils.release(connection, pre, rs);
		
		//只要关闭了connection就要连接池中移除，不然会 报一个关闭后仍然运行的错误。
		ConnectionsPool.remove(connection);
		return user;
	}

	public User getSelectIdOne(int user_id) {
		// TODO Auto-generated method stub
		return null;
	}
}
